package io.homework;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲输出流:数据的缓冲区问题
 */
public class FlushDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("test.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        String line = "每天背上小书包 花儿对我笑";
        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);

        bos.flush();
        System.out.println("写出完毕");

        /*
        FileOutputStream fos = new FileOutputStream("test.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        String line = "每天背上小书包 花儿对我笑";
        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);

        bos.flush();
        System.out.println("写出完毕");
         */
    }
}
